<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
				$("#btnExport").click(function(){
					top.$.jBox.confirm("确认要导出商品数据吗？","系统提示",function(v,h,f){
						if(v=="ok"){
							$("#searchForm").attr("action","${ctx}/sys/tbShopProduct/exportShopProduct");
							$("#searchForm").submit();
						}
					},{buttonsFocus:1});
					top.$('.jbox-body .jbox-icon').css('top','55px');
				});
			//价格点击编辑
			$("span[name='proPriceSpan']").click(function(){
				$(this).hide();
				$(this).next("input").show();
			});
			//修改价格 ajax交互
			$("input[name='proPriceInput']").blur(function(){
				var productId = $(this).next("input").val();
				var price = $(this).val();
				var proSpan = $(this).prev("span");
				var proInput = $(this);
				//后台交互
				$.ajax({
					type : "POST",
					url : "${ctx}/sys/tbShopProduct/updateProductPriceAjax",
					data : {
						id:productId,
						price:price
					},
					dataType : "JSON",
					beforeSend:function(XMLHttpRequest){
						showMask();
					},
					success : function(data) {
						if(data!=''){
							hideMask();
							$(proInput).hide();
							$(proSpan).html(price);
							$(proSpan).show();
							alert("修改成功！");
						}
					}
				});
			})
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function showMask(){
			$("#mask").css("height",$(document).height());
			$("#mask").css("width",$(document).width());
			$("#mask").show();
		}
		//隐藏遮罩层
		function hideMask(){
			$("#mask").hide();
		}
	</script>
	<style>
		/*ajax 加载中*/
		.mask {
			text-align: center;
			background-image: url("../../../../static/images/loading.gif");
			background-repeat: no-repeat;
			background-position-x: 50%;
			background-position-y: 50%;
			position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
			z-index: 1002; left: 0px;
			opacity:0.5; -moz-opacity:0.5;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/tbShopProduct/">商品管理</a></li>
		<li hidden="hidden"><a href="${ctx}/sys/tbShopProduct/form"  >库存管理添加</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="tbShopProduct" action="${ctx}/sys/tbShopProduct/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>商品名称：</label>
				<form:input path="productName" htmlEscape="false" maxlength="11" class="input-medium"/>
			</li>
			<li> &nbsp; &nbsp; 商品类别:
				<select name="shopCategoyr" class="input-medium">
					<option value="" >请选择</option>
					<option value="4" <c:if test="${tbShopProduct.shopCategoyr==4}">selected</c:if>>便利生活</option>
					<option value="3" <c:if test="${tbShopProduct.shopCategoyr==3}">selected</c:if>>生活预定</option>
					<option value="2" <c:if test="${tbShopProduct.shopCategoyr==2}">selected</c:if>>海外代购</option>
				</select>
				<%--<form:input path="reserveFlag" htmlEscape="false" maxlength="3" class="input-medium"/>--%>
			</li>
			<li class="btns">&nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnExport" class="btn btn-primary" type="button" value="导出"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<div id="mask" class="mask" style="display: none;"></div>
	<sys:message content="${message}"/>
	<span><font style="color: #00A6C7">${message1}</font></span>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>商品名称</th>
				<th>图片</th>
				<th>商品类别</th>
				<th>属性</th>
				<th>单位</th>
				<th>售价</th>
				<th>库存</th>
				<th>是否维护库存</th>
				<th>是否可用物业钱包</th>
				<c:choose>
					<c:when test="${flag==1}">
					</c:when>
					<c:otherwise>
						<th>是否预定商品</th>
						<th>是否每天</th>
						<th>预定起售时间</th>
						<th>预定终售时间</th>
					</c:otherwise>
				</c:choose>
				<%--<th>创建时间</th>--%>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="tbShopProduct">
			<tr>
				<td><a href="${ctx}/sys/tbShopProduct/form?id=${tbShopProduct.id}" title="${tbShopProduct.productName}" >
						${fn:substring(tbShopProduct.productName, 0,4)}
				</a></td>
				<td>
					<a href="${tbShopProduct.img}" target="_blank">
						<img width="70" height="70" src="${tbShopProduct.img}" >
					</a>
				</td>
                <td>
                       <%-- ${tbShopProduct.categoryName}--%>
					<c:choose>
						<c:when test="${tbShopProduct.shopCategoyr==4}">生活预定</c:when>
						<c:when test="${tbShopProduct.shopCategoyr==3}">便利生活</c:when>
						<c:when test="${tbShopProduct.shopCategoyr==2}">海外代购</c:when>
					</c:choose>
                </td>
				<td>
					<%--<c:forEach items="${tbShopProduct.productAttr}" var="attr">
						${attr.productAttrOption}&nbsp;&nbsp;
					</c:forEach>--%>
							${tbShopProduct.attr}
				</td>
				<td>
						<%--<c:forEach items="${tbShopProduct.productAttr}" var="attr">
                            ${attr.productAttrOption}&nbsp;&nbsp;
                        </c:forEach>--%>
						${tbShopProduct.productSize}
				</td>
				<td>
					<span name="proPriceSpan">${tbShopProduct.price}</span>
					<input name="proPriceInput" value="${tbShopProduct.price}" style="display: none;width:50px;"/>
					<input name="proName" value="${tbShopProduct.id}" type="hidden"/>
				</td>

				<td>
					${tbShopProduct.storeNum}
				</td>
				<td>
					<c:choose>
						<c:when test="${tbShopProduct.ismainStoreNum==0}">

							<span>否</span>

						</c:when>
						<c:when test="${tbShopProduct.ismainStoreNum==1}">

							<span>是</span>

						</c:when>
					</c:choose>
				</td>
				<td>
					<c:choose>
						<c:when test="${tbShopProduct.isUseMqWallet==0}">

							<span>否</span>

						</c:when>
						<c:when test="${tbShopProduct.isUseMqWallet==1}">

							<span>是</span>

						</c:when>
					</c:choose>
				</td>
				<c:choose>
					<c:when test="${flag==1}">
					</c:when>
					<c:otherwise>
						<td>
							<c:choose>
								<c:when test="${tbShopProduct.reserveFlag==1}">
									<span>是</span>
								</c:when>
								<c:otherwise>否</c:otherwise>
							</c:choose>
						</td>
						<%--<td>
							<c:choose>
								<c:when test="${tbShopProduct.gender==0}">
									<span>是</span>
								</c:when>
								<c:otherwise>否</c:otherwise>
							</c:choose>
						</td>--%>
						<c:choose>
							<c:when test="${tbShopProduct.gender==0&&tbShopProduct.reserveFlag==1}">
								<td>否</td>
								<td>
									<fmt:formatDate value="${tbShopProduct.reserveStartTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
								</td>
								<td>
									<fmt:formatDate value="${tbShopProduct.reserveEndTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
								</td>
							</c:when>
							<c:when test="${tbShopProduct.gender==1}">
								<td>是</td>
								<td>
									<fmt:formatDate value="${tbShopProduct.reserveStartTime}" pattern="HH:mm"/>
								</td>
								<td>
									<fmt:formatDate value="${tbShopProduct.reserveEndTime}" pattern="HH:mm"/>
								</td>
							</c:when>
							<c:otherwise>
								<td></td>
								<td>
								</td>
								<td>
								</td>
							</c:otherwise>
						</c:choose>
					</c:otherwise>
				</c:choose>
			<%--	<td>
					<fmt:formatDate value="${tbShopProduct.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>--%>
				<td>
    				<a href="${ctx}/sys/tbShopProduct/form?id=${tbShopProduct.id}">修改</a><br/>
					<a href="${ctx}/sys/tbShopProduct/delete?id=${tbShopProduct.id}" onclick="return confirmx('确认要删除该库存管理吗？', this.href)">删除</a>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>